package com.canbot.u05.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.canbot.u05.MainApplication;
import com.canbot.u05.R;
import com.canbot.u05.glide.GlideApp;
import com.canbot.u05.socket.IpMsgConst;

import java.util.Random;

/**
 * 倒计时自动取消对话框
 */
public class PicPreviewDialog extends Dialog {

        private Context mContext;

        private String path;

        private ImageView ivPicPreview;

        private Button btnBack;

        private final String TAG = "CenterDialog";


        public PicPreviewDialog(Context context, int style, String path) {
                super(context, style);
                this.mContext = context;
                this.path = path;

        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                initView();
        }

        private void initView() {
                LayoutInflater layoutInflater = LayoutInflater.from(mContext);
                View viewDialog = layoutInflater.inflate(R.layout.dialog_pic_preview_center, null);
                setContentView(viewDialog);
                ivPicPreview = (ImageView) viewDialog.findViewById(R.id.preview_pic);
                btnBack = (Button) viewDialog.findViewById(R.id.btn_back);

                setCanceledOnTouchOutside(true);

                setImageDrawable(path);

                btnBack.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                                dismiss();
                        }
                });


        }

        /**
         * 设置路径下的图片对应的缩略图
         */
        public void setImageDrawable(final String path) {
                GlideApp.with(getContext()).clear(ivPicPreview);
                GlideApp.with(getContext())
                        .asDrawable()
                        .load(IpMsgConst.HTTP_URL_CHEST + path.replace("/uupic/","/uupic_thumb/"))
                        .thumbnail(0.1f)
                        .diskCacheStrategy(DiskCacheStrategy.ALL)//缓存策略
                        .skipMemoryCache(false)
                        .placeholder(R.drawable.sales_banner01)//占位图
                        .error(R.drawable.ic_picture_loadfailed)
                        .override(100, 100)
                        .into(ivPicPreview);
        }

        @Override
        public void show() {
                super.show();
        }

        @Override
        public void cancel() {
                super.cancel();
        }
}
